from django.contrib.auth.models import AbstractUser
from django.db import models
import uuid

from rest_framework.fields import FileField


# Create your models here.

class uploadFile(models.Model):
    """
    头像，文件上传
    """
    id = models.AutoField(primary_key=True)
    file = models.FileField(null=True, blank=True,upload_to='%Y/%m/%d/', default="default.jpg")  # 文件讲上传至media/年/月/日/文件夹下
    # headImg   = models.ImageField(upload_to = 'media', default="default.jpg")

class user(models.Model):
    """
    用户表
    """
    id = models.CharField(max_length=30, primary_key=True)
    password = models.CharField(max_length=200, default='123456')
    type = models.IntegerField(default=3)  # 0 为管理员，1为教师， 2为学生, 3为维修人员, 4为已注销
    pid = models.ForeignKey(to='uploadFile', to_field='id',default=1, on_delete=models.SET_DEFAULT)  # 头像


class equipment(models.Model):
    """
    设备表
    """
    id = models.AutoField(primary_key=True)
    category = models.CharField(max_length=10)  # 类名
    deviceName = models.CharField(max_length=50)  # 设备名
    model = models.CharField(max_length=50)  # 型号
    price = models.FloatField()  # 单价
    unit = models.IntegerField()  # 数量
    exist = models.IntegerField(default=0)  # 当前批次现存可使用设备数
    purchaseDate = models.DateField()  # 购置日期
    manufacturer = models.CharField(max_length=50)  # 生产厂家
    purchaser = models.CharField(max_length=20)  # 购买人
    batch = models.DateTimeField()  # 批次（当同一品牌与型号的设备入库时，要记录设备入库的批次信息）


class epRunning(models.Model):
    """
    运行设备表
    """
    # id = models.CharField(primary_key=True, max_length=32, default=str(uuid.uuid4().hex), editable=False)  # 主键
    id = models.AutoField(primary_key=True)
    place = models.CharField(max_length=20)  # 使用位置
    belongIn = models.CharField(max_length=10, null=True)  # 属于哪个机房
    # eid = models.ForeignKey(to='equipment', to_field='id', related_name='equipment_deviceName', on_delete=models.CASCADE)  # 属于哪一类产品
    eid = models.ForeignKey(to='equipment', to_field='id', on_delete=models.CASCADE)  # 属于哪一类产品
    isActive = models.BooleanField(default=True)  # 是否可用
    inUsing = models.BooleanField(default=False)  # 是否正在被使用
    enableDate = models.DateField()  # 投入使用的日期


class repair(models.Model):
    """
    维修记录表
    """
    id = models.AutoField(primary_key=True)
    eprid = models.ForeignKey(to='epRunning', to_field='id', on_delete=models.CASCADE)
    uid = models.ForeignKey(to='user', to_field='id', on_delete=models.CASCADE)  # 责任经办人
    status = models.IntegerField(default=0)  # 维修状态： 0 报修中； 1 检修中； 2 已处理
    result = models.CharField(max_length=255, null=True, blank=True)  # 维修结果简述
    repairDate = models.DateField()  # 报修日期
    repairFactory = models.CharField(max_length=50, null=True, blank=True)  # 维修厂家
    cost = models.FloatField(null=True, blank=True)  # 维修费用


class scrap(models.Model):
    """
    报废表
    """
    id = models.AutoField(primary_key=True)
    # eprid = models.ForeignKey(to='epRunning', to_field='id', on_delete=models.CASCADE)
    eid = models.ForeignKey(to='equipment', to_field='id', on_delete=models.CASCADE)
    scrapDate = models.DateField()  # 报废日期

# class test(models.Model):
#     """
#     测试
#     """
#     class meta:
#         db_instance_qs



